package flc.ast.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.io.File;

import flc.ast.R;
import flc.ast.bean.MyAlbumBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.FileP2pUtil;
import stark.common.basic.utils.FileUtil;

public class MusicAlbumAdapter extends StkProviderMultiAdapter<String> {

    public MusicAlbumAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(100));
        addItemProvider(new MusicAlbumProvider());
    }

    private class MusicAlbumProvider extends BaseItemProvider<String> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_music_album;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, String bean) {
            if (TextUtils.isEmpty(bean)) {
                baseViewHolder.setImageResource(R.id.ivMusicAlbumItemImg, R.drawable.aimage_xjxc);
                baseViewHolder.getView(R.id.ivMusicAlbumItemAdd).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.llMusicAlbumItem).setVisibility(View.GONE);
            } else {
                baseViewHolder.getView(R.id.ivMusicAlbumItemAdd).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.llMusicAlbumItem).setVisibility(View.VISIBLE);
                Glide.with(getContext()).load(bean)
                        .into((ImageView) baseViewHolder.getView(R.id.ivMusicAlbumItemImg));
                baseViewHolder.setText(R.id.tvMusicAlbumItemDate, TimeUtils.millis2String(FileUtils.getFileLastModified(bean), "yyyy.MM.dd"));
            }
        }
    }
}
